<?php


namespace api\web\controller;


use api\web\model\NavModel;
use cmf\controller\RestBaseController;
use think\facade\Filesystem;

class NavController extends RestBaseController
{
    public function index(){
        $list =NavModel::order('id','desc')->select();
        $this->success('首页导航菜单列表',$list);
    }
    //编辑
    public function update(){
        //接收
        $data=input('post.');
        //去除image数据
        unset($data['image']);
        //修改图片
        $image = request()->file('image');
        $result = Filesystem::disk('public')->putFile('NavImage',$image);
        $image2 =   request()->domain().DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.$result;
        $dh = NavModel::find($data['id']);
        $dh->image=$image2;
        $dh->title=$data['title'];
        $dh->url=$data['url'];
        if($dh->save()){
            $this->success('保存成功',[
                'msg'=>$data,$image2,
            ]);
        }else{
            $this->error('保存失败');
        }
    }
}